// JavaScript Document
$(document).ready(function() {
 $(window).load(function(){
	 var isblock=false;
	$('.detailTopWin').mousemove(function(eve){
		var e=eve||window.event;
		 
            var bigL = e.pageX-$('.detailTopWin').offset().left-87;
            var bigT = e.pageY-$('.detailTopWin').offset().top-87;

            if(bigL<0){bigL=0;}
            if(bigT<0){bigT=0;}
            if(bigL>$('.detailTopWin').width()-180){bigL=$('.detailTopWin').width()-180}
            if(bigT>$('.detailTopWin').height()-180){bigT=$('.detailTopWin').height()-180}

            $('.big').css({'left':bigL,'top':bigT})  
			$('#detailTopBigWinImg').css({left:(-bigL/360*800),top:(-bigT/360*800) })

		}).hover(function(event) {
            $(this).children('.big').toggle();
			$('.detailTopBigWin').toggle();
        });
//--------------以上为放大镜效果------------------------------------------
$('.detailTopC>.p5 .span3').click(function(){
	var num=$('.detailTopC>.p5 #checkedNum').val();
	num++;
	if(num>$('.detailTopC>.p5 .last').html()){num=$('.detailTopC>.p5 .last').html()}
	$('.detailTopC>.p5 #checkedNum').val(num);
	})	;
$('.detailTopC>.p5 .span2').click(function(){
	var num=$('.detailTopC>.p5 #checkedNum').val();
	num--;
	if(num<1){num=1}
	$('.detailTopC>.p5 #checkedNum').val(num);
	})	
		
		
//------------------以上为购物数量部分-----------------------------------------		

$('.detailTopC>.p6 .a2').click(function(){
	
	if(getCookie('zidong')){
	var num=$('.detailTopC>.p5 #checkedNum').val();
	
	var num2=$('#carnum').html();
	var str=$('.detailTopC>.p1').html()+' x ';//获取商品名称；
	var dl=document.createElement('dl');
	var dt=document.createElement('dt');
	var dd=document.createElement('dd');
	var span=document.createElement('span');
	var price=$('#detailPrice').html();
	span.innerHTML='X'
	span.onclick=function(){
		var dl=$(this).parent('dl');
		dl.css('display','none');
		var num3=parseInt($('#carnum').html())-num
		
		$('#carnum').html(num3);
	$('#bodyRightCarNum').html(num3);
	
		}
	var img=document.createElement('img');//创建购物车动画效果
	img.src=$('#detailTopWinImg').attr('src')
	dt.appendChild(img);
	dd.innerHTML=str+num;
	dl.appendChild(dt);
	dl.appendChild(dd);
	dl.appendChild(span)
	$('.bodyRightCar').append($(dl));
	var img=document.createElement('img');//创建购物车动画效果
	img.src=$('#detailTopWinImg').attr('src')
	$(img).css({position:'fixed',left:20,top:200})
	document.body.appendChild(img);
	$(img).animate({left:1260,top:320,width:0,height:0},1000);
	$('#carnum').html(parseInt(num)+parseInt(num2));
	$('#bodyRightCarNum').html(parseInt(num)+parseInt(num2));
	//---------------删除商品代码-------------------------------------------------
	
	if(getCookie('shopingCarNum')){
		var shopingCarNum=getCookie('shopingCarNum');
		shopingCarNum=parseInt(shopingCarNum)+1
		setCookie(shopingCarNum,'[{src:"'+$('#detailTopWinImg').attr('src')+'",name:"'+str+'",num:"'+num+'",price:"'+price+'"}]',10)
		setCookie('shopingCarNum',shopingCarNum,10)
		}
	else{
		setCookie('shopingCarNum',0,10);
	
		setCookie(0,'[{src:"'+$('#detailTopWinImg').attr('src')+'",name:"'+str+'",num:"'+num+'",price:"'+price+'"}]',10)
		
		}
	}
	
	else{
		alert('亲！ 请先登录，才能买东西哦');
		
		}
	//---------------以上为存储商品信息----------------------------------
	
	
	})

				
//-----------------以上为购物车按钮效果部分-----------------------------------------		
		
$('.detailLunbo ul li img').click(function(){
	var str=$(this).attr('src');
	$('#detailTopWinImg').attr('src',str);
	$('#detailTopBigWinImg').attr('src',str);
	})



//-------------以上为详情页左边小轮播图-----------------------------------

$('.detailMainR4 li').click(function(){
	$('.detailMainR4 li').removeClass('active');
	$(this).addClass('active');
	})
	
$('.detailNav a').not('.last').click(function(){
	$('.detailNav a').not('.last').removeClass('active');
	$(this).addClass('active')
	})
//-----------以上为详情页中间导航部分------------------------
$(window).scroll(function(){
	
	
	var scollTop=$(window).scrollTop();
	
	if(scrollTop>969){$('.detailMainR2').css({position:'fixed',top:0,right:0})}
	})



$('.header-bottom>p').mouseover(function(){
	$('.indexNavL').css('display','block');
	$('.indexNavL p').mouseover(function(){
		$('.indexNavC').css('left',220)
		})
	$('.indexNavC').mouseout(function(){
		$('.indexNavL').css('display','none');
	
		});
	})









if(getCookie('shopingCarNum')){
		var num=getCookie('shopingCarNum');
		var obj=[];
		var sum=0;
		
		for(var i=0;i<=num;i++){
			
			obj[i]=eval(getCookie(i));
			sum+=parseInt(obj[i][0].num);
			var dl=document.createElement('dl');
			var dt=document.createElement('dt');
			var dd=document.createElement('dd');
			var img=document.createElement('img');
			var src=obj[i][0].src;
			
			img.src=src
			
			dt.appendChild(img);
			dd.innerHTML=obj[i][0].name+' x '+obj[i][0].price;
			dl.appendChild(dt);
			dl.appendChild(dd);
			$('.bodyRightCar').append($(dl))
			}
		$('#bodyRightCarNum').html(sum);
		$('#carnum').html(sum)
		
		}
	
	//以上为初始话网页时，右边购物车动态效果

$('.detailTuijian ul li img').mouseover(function(){
	var ind=$('.detailTuijian ul li img').index($(this));
	$('.detailTuijian ul li p').animate({top:120},200).stop().eq(ind).animate({top:100},200);
	$(this).mouseout(function(){
		$('.detailTuijian ul li p').stop().animate({top:120},200)
		})
	})
		
		
		
//--------------------------		
		
		
		
		
		})
});
